<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <form action="" name="formTest" id="myForm">
        <input id="fileId" type="file" accept=".csv,.xls,.xlsx" name="file" onChange="changeExcel(event)" />
    </form>
</body>
<script>
    let myForm = document.getElementById("myForm")
    const changeExcel = (ev) => {
        const files = ev.target.files;
        console.log(files);
        if (files.length < 0) {
        alert('没有上传');
        return false;
        } else if (!/\.(csv|xls|xlsx)$/.test(files[0].name.toLowerCase())) {
        alert('您上传的文件格式不正确');
        return false;
        } else {
        let param = new FormData(myForm); //创建form对象
        // 通过 entries() 遍历 FormData 对象中所有的 key 和 value。
        for(let pair of param.entries()){
                console.log(pair[0] +"," + pair[1]);
            }
        }
    };
</script>
</html>